<?php
/**
 * Created by PhpStorm.
 * User: yuanjie
 * Date: 16/5/20
 * Time: 上午10:28
    // get_profit_report : 订单类-毛利率分析
    // get_check_inventory_supply : 库存类-盘点明细
    // get_storage_detail : 库存类-入库明细
    // get_out_detail : 库存类-出库明细
    // get_supply_stock_new : 库存类-结算进销存耗材明细 and 库存类-结算进销存分类统计
    // get_supply_stock : 库存类-进销存耗材明细 and 库存类-进销存分类统计
    // get_engineer_work_detail : 员工绩效-技师工作绩效明细 and 员工绩效-技师工作绩效统计
    // get_company_credit_detail : 经营情况-应收账款明细
    // get_company_credit_sum : 经营情况-应收账款统计
    // get_export_detail : 经营情况-油品营业分析 and 经营情况-耗材营业分析 and 订单类-订单维修耗材出库明细
    // get_work_hour_product : 经营情况-服务营业分析
    // get_order_income : 订单类-订单明细
    // get_order_derate_detail : 订单类-订单减免明细
    // get_order_parts : 订单类-订单耗材明细 and 订单类-订单耗材分类统计
    // get_work_hour_report : 订单类-订单工时明细 and 订单类-订单服务分类统计
    // temp_get_order_detail : 订单类-未结算订单明细
    // temp_get_work_hour_report : 订单类-未结算订单工时分类明细
    // temp_get_export_detail : 订单类-未结算订单维修产品出库明细
 */
class ReportController extends BaseController{

     /**
      * @Author:      lyt
      * @DateTime:    2017-03-01 10:48:12
      * @Description: 应收统计
      */
    public function get_yingshou(){
        $validator = Validator::make(Input::all(),
            array(
                'shop_id' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do{
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }
            $shop_id = Input::get('shop_id');

            $response = ReportService::yingshou($shop_id);

        }while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_yingshou", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    /**
    * @Author:      lyt
    * @DateTime:    2016-09-21 16:06:13
    * @Description: 用与企业订单的统计 
    */
    public function get_bpjx_detail(){
        $validator = Validator::make(Input::all(),
            array(
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do{
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            $response = ReportTask::task('get_bpjx_detail',$begin_date,$end_date,$shop_id);

        }while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_bpjx_detail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

   /**
    * @Author:      lyt
    * @DateTime:    2016-09-21 16:06:13
    * @Description: 用与企业订单的统计 
    */
    public function get_enterprice_order_detail(){
        $validator = Validator::make(Input::all(),
            array(
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do{
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            $response = ReportTask::task('get_enterprice_order_detail',$begin_date,$end_date,$shop_id);

        }while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_enterprice_order_detail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    /**
     * @Author:      lyt
     * @DateTime:    2016-11-10 16:56:41
     * @Description: 报表
     */
    public function get_insurance_detail(){
        $validator = Validator::make(Input::all(),
            array(
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do{
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');
            $begin_bill = Input::get('begin_bill');
            $end_bill = Input::get('end_bill');

            $response = Report::get_insurance_detail($begin_date,$end_date,$shop_id,$begin_bill,$end_bill);

        }while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_insurance_detail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    /**
     * @Author:      lyt
     * @DateTime:    2016-08-29 09:51:08
     * @Description: 技师耗材业绩的明细
     */
    public function get_engineer_supply_detail(){
        $validator = Validator::make(Input::all(),
            array(
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do{
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            $response = ReportTask::task('get_engineer_supply_detail',$begin_date,$end_date,$shop_id);

        }while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_engineer_supply_detail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    /**
     * @Author:      lyt
     * @DateTime:    2016-08-25 10:52:54
     * @Description: 获取流水表
     */
    public function total_operating_data(){
        $validator = Validator::make(Input::all(),
            array(
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do{
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            $b_begin_date=date('Y-m-d 00:00:00',strtotime('-1 year',strtotime($begin_date)));
            $b_end_date=date('Y-m-d 23:39:59',strtotime('-1 year',strtotime($end_date)));
            $temp=array();
            $response = ReportOperatingData::where('shop',$shop_id)
                    ->whereBetween('date',array($begin_date,$end_date))
                    ->get()
                    ->toArray();
            $temp['date']=$response;
            $array=DB::select("SELECT `key`,sum(`value`) as `value` FROM `report_operating_data` where  shop=? and date BETWEEN ? and ? group by `key`",array($shop_id,$b_begin_date,$b_end_date));
            $temp['before']=$array;

        }while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_order_derate_detail", 'input' =>Input::all() ,"output" => $temp));
        return json_encode($temp);
    }

    /**
     * @Author:      lyt
     * @DateTime:    2016-08-17 17:02:51
     * @Description: 用于 退货详情的报表
     */
    public function get_return_order_detail(){
        $validator = Validator::make(Input::all(),
            array(
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );
        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do{
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            $response = ReportTask::task('get_return_order_detail',$begin_date,$end_date,$shop_id);

        }while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_order_derate_detail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    /**
     * @Author:      lyt
     * @DateTime:    2016-07-20 09:59:37
     * @Description: 获取未结算的订单信息
     */
    public function temp_get_order_detail(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            //$response = Report::temp_get_order_detail($shop_id);
            $response = ReportTask::task('temp_get_order_detail','2000-01-01','2000-01-01',$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "temp_get_order_detail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    public function get_order_derate_detail(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            //$response = Report::get_order_derate_detail($begin_date,$end_date,$shop_id);
            $response = ReportTask::task('get_order_derate_detail',$begin_date,$end_date,$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_order_derate_detail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
    
    public function get_order_parts(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            //$response = Report::get_order_parts($begin_date,$end_date,$shop_id);
            $response = ReportTask::task('get_order_parts',$begin_date,$end_date,$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_order_parts", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    /**
     * @Author:      lyt
     * @DateTime:    2016-06-01 21:25:41
     * @Description: 用于统计
     */
    public function get_work_hour_product(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            $response=ReportDateReocrd::getDate($begin_date,$end_date,$shop_id,"get_work_hour_product");
            //$response = Report::get_work_hour_product($begin_date,$end_date,$shop_id);
            // $response = ReportTask::task('get_work_hour_product',$begin_date,$end_date,$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_work_hour_product", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    public function get_order_income(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            //$response = Report::get_order_income($begin_date,$end_date,$shop_id);
            $response = ReportTask::task('get_order_income',$begin_date,$end_date,$shop_id);
            // $response=ReportDateReocrd::getDate($begin_date,$end_date,$shop_id,"get_order_income");

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_order_income", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    public function get_work_hour_report(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            $response=ReportDateReocrd::getDate($begin_date,$end_date,$shop_id,"get_work_hour_report");
            //$response = Report::get_work_hour_report($begin_date,$end_date,$shop_id);
            // $response = ReportTask::task('get_work_hour_report',$begin_date,$end_date,$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_work_hour_report", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    /**
     * @Author:      lyt
     * @DateTime:    2016-07-19 15:38:03
     * @Description: 当前
     */
    public function temp_get_work_hour_report(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            //$response = Report::temp_get_work_hour_report($shop_id);
            $response = ReportTask::task('temp_get_work_hour_report','2000-01-01','2000-01-01',$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "temp_get_work_hour_report", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    public function get_profit_report(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

         
            $response=ReportDateReocrd::getDate($begin_date,$end_date,$shop_id,"get_profit_report");
            // $response = ReportTask::task('get_profit_report',$begin_date,$end_date,$shop_id);
            // $response = Report::get_profit_report($begin_date,$end_date,$shop_id);

        } while (false);
        Log::info("info", array("system" => "report" ,"event" => "get_profit_report", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    public function get_check_inventory_supply(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            //$response = Report::get_check_inventory_supply($begin_date,$end_date,$shop_id);
            $response = ReportTask::task('get_check_inventory_supply',$begin_date,$end_date,$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_check_inventory_supply", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    public function get_storage_detail(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            $response = Report::get_storage_detail($begin_date,$end_date,$shop_id);
            // $response = ReportTask::task('get_storage_detail',$begin_date,$end_date,$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_storage_detail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    public function get_export_detail(){
        //todo 增加验证
        $export_detail = array();
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

//        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            $response=ReportDateReocrd::getDate($begin_date,$end_date,$shop_id,"get_export_detail");
//            $date=ReportDateReocrd::whereBetween("date",array($begin_date,$end_date))->where("shop_id",$shop_id)->where("report_type","get_export_detail")->get();
//            foreach ($date as $_d) {
//                $temp=unserialize(gzuncompress(base64_decode($_d->data)));
//                foreach ($temp as $_t) {
//                    array_push($export_detail,$_t);
//                }
//            }

            // $response = ReportTask::task('get_export_detail',$begin_date,$end_date,$shop_id);
            // Log::info("info", array("system" => "report" ,"event" => "get_export_detail", 'input' =>Input::all() ,"output" => $response));
        } while (false);        
        return json_encode($response);
    }

    /**
     * @Author:      lyt
     * @DateTime:    2016-07-19 18:00:53
     * @Description: 用于未结算的耗材出库配件统计 
     */
    public function temp_get_export_detail(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            //$response = Report::temp_get_export_detail($shop_id);
            $response = ReportTask::task('temp_get_export_detail','2000-01-01','2000-01-01',$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "temp_get_export_detail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    public function get_order_parts_cost(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            $response = Report::get_order_parts_cost($begin_date,$end_date,$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_order_parts_cost", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    public function get_company_credit_detail(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            //$response = Report::get_company_credit_detail($begin_date,$end_date,$shop_id);
            $response = ReportTask::task('get_company_credit_detail',$begin_date,$end_date,$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_company_credit_detail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    public function get_company_credit_sum(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            //$response = Report::get_company_credit_sum($begin_date,$end_date,$shop_id);
            $response = ReportTask::task('get_company_credit_sum',$begin_date,$end_date,$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_company_credit_sum", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    public function get_engineer_work_detail(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            //$response = Report::get_engineer_work_detail($begin_date,$end_date,$shop_id);
            $response = ReportTask::task('get_engineer_work_detail',$begin_date,$end_date,$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_engineer_work_detail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }

    /**
     * @Author:      lyt
     * @DateTime:    2016-06-03 11:19:08
     * @Description: 进销存的查询
     */
    public function get_supply_stock(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'date_id' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $date_id = Input::get('date_id');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
            //$response = Report::get_supply_stock($begin_date,$end_date,$date_id,$shop_id);
            $response = ReportTask::task('get_supply_stock',$begin_date,$end_date,$date_id,$shop_id,$date_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_supply_stock", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }


    /**
     * @Author:      lyt
     * @DateTime:    2016-06-03 11:19:08
     * @Description: 进销存的查询
     */
    public function get_supply_stock_new(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'date_id' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            //传入参数
//            $token = Input::get('token');
            $date_id = Input::get('date_id');
            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');

            //验证token
//            $car_data = MaintenanceCars::getMaintenanceCarByToken($token);
//            if(is_numeric($car_data) && $car_data < 0){
//                $response = Lang::get("ods_error.token_check_error_12005");
//                break;
//            }
           $response = Report::get_supply_stock_new($begin_date,$end_date,$date_id,$shop_id);
            // $response = ReportTask::task('get_supply_stock_new',$begin_date,$end_date,$shop_id,$date_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_supply_stock_new", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }



    /**
     * @Author:      lyt
     * @DateTime:    2016-06-29 14:56:40
     * @Description: 获取出库查询
     */
    public function get_out_detail(){
        //todo 增加验证
        $validator = Validator::make(Input::all(),
            array(
//                'token' => 'required',
                'shop_id' => 'required',
                'begin_date' => 'required',
                'end_date' => 'required',
            )
        );

//        $response = array('code' => 0, 'msg' => 'ok', 'result' => array());
        do {
            if ($validator->fails()) {
                $response = Lang::get("error.user_token_args_error_1005");
                break;
            }

            $shop_id = Input::get('shop_id');
            $begin_date = Input::get('begin_date');
            $end_date = Input::get('end_date');
            $response=ReportDateReocrd::getDate($begin_date,$end_date,$shop_id,"get_out_detail");
//            $date=ReportDateReocrd::whereBetween("date",array($begin_date,$end_date))->where("shop_id",$shop_id)->where("report_type","get_out_detail")->get();
//            $export_detail = array();
//            foreach ($date as $_d) {
//                $temp=unserialize(gzuncompress(base64_decode($_d->data)));
//                foreach ($temp as $_t) {
//                    array_push($export_detail,$_t);
//                }
//            }
            
            // $response = Report::get_out_detail($begin_date,$end_date,$shop_id);
            // $response = ReportTask::task('get_out_detail',$begin_date,$end_date,$shop_id);

        } while (false);
        // Log::info("info", array("system" => "report" ,"event" => "get_out_detail", 'input' =>Input::all() ,"output" => $response));
        return json_encode($response);
    }
}